<template>
  <el-dialog custom-class="app_dialogadd" :close-on-click-modal="!props.appDialog.closeModal" v-model="props.appDialog.visible" :width="props.appDialog.width" destroy-on-close :append-to-body="props.appDialog.append" :before-close="handleClose" @closed="closed">
    <template #title>
      <div class="dialog_header">{{ props.appDialog.title }}</div>
    </template>
    <section>
      <slot></slot>
    </section>
    <template #footer v-if="!props.appDialog.isHiddenFoot">
      <div class="footer">
        <div>
          <span v-show="props.appDialog.showFootcontent" class="text">{{ props.appDialog.footContent }}</span>
        </div>
        <span class="dialog_footer">
          <el-button v-if="props.appDialog.moreBtn" @click="props.appDialog.moreBtn">{{ props.appDialog.moreBtnText }} </el-button>
          <el-button v-if="props.appDialog.cancel" @click="props.appDialog.cancel">{{ props.appDialog.cancelText }} </el-button>
          <el-button v-if="props.appDialog.save" @click="props.appDialog.save">{{ props.appDialog.saveText }} </el-button>
          <el-button v-if="props.appDialog.submit" :disabled="props.appDialog.isDisable" :type="!props.appDialog.isDisable ? 'primary' : 'info'" @click="props.appDialog.submit">{{ props.appDialog.submitText }}</el-button>
        </span>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
  import { defineProps, ref, reactive } from 'vue'
  interface Props {
    isHiddenFoot?: boolean
    width?: '30%'
    visible: boolean
    showFootcontent?: false
    footContent?: ''
    title: string
    append?: boolean
    uploadShow?: boolean
    cancelText?: string
    saveText?: string
    submitText?: string
    moreBtnText?: string
    isDisable?: boolean
    cancel?: () => void
    save?: () => void
    submit?: () => void
    moreBtn?: () => void
  }
  const emit = defineEmits(['close', 'closed'])
  const props = defineProps<{
    appDialog: {
      type: Props
      require: true
    }
  }>()

  const handleClose = (done: () => void) => {
    props.appDialog.cancel && props.appDialog.cancel()
    done()
    emit('close')
  }
  const closed = () => {
    emit('closed')
  }
</script>
